﻿using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace revitDemo
{
    public class 沿着圆放样:RevietBase
    {
        public 沿着圆放样(ExternalCommandData commandData) : base(commandData)
        {
        }

        public override void Test()
        {

            //竖着圆环();
            坐标系();
            横着圆弧();

        }





        public void 横着圆弧()
        {
            double z =-5;
            double _x = 0;

            var l1 = Line.CreateBound(new XYZ(3- _x, 0, z), new XYZ(3 - _x, 10, z));
            var l2 = Line.CreateBound(new XYZ(3 - _x, 10, z), new XYZ(4 - _x, 10, z));
            var l3 = Line.CreateBound(new XYZ(4 - _x, 10, z), new XYZ(4 - _x, 0, z));
            var l4 = Line.CreateBound(new XYZ(4 - _x, 0, z), new XYZ(3 - _x, 0, z));
            List<Curve> profile1 = new List<Curve>() { l1, l2, l3, l4 };

            //foreach (var item in profile1)
            //{
            //    OpenTransaction("bb3", x =>
            //    {
            //        item.CreateModelCurve(x);

            //    });
            //}


            CurveLoop curveLoop = CurveLoop.Create(profile1);
            var solid = CreateCone(new XYZ(_x, 0,z), curveLoop);
            OpenTransaction("223", solid);

        }


        public void 竖着圆环()
        {
            XYZ center = XYZ.Zero;
            XYZ px = 3 * XYZ.BasisX;
            XYZ pz = 10 * XYZ.BasisZ;

            List<Curve> profile = new List<Curve>();

            profile.Add(Line.CreateBound(center, px));
            profile.Add(Line.CreateBound(px, pz));
            profile.Add(Line.CreateBound(pz, center));


            var l1 = Line.CreateBound(new XYZ(3, 0, 0), new XYZ(4, 0, 0));
            var l2 = Line.CreateBound(new XYZ(4, 0, 0), new XYZ(4, 0, 10));
            var l3 = Line.CreateBound(new XYZ(4, 0, 10), new XYZ(3, 0, 10));
            var l4 = Line.CreateBound(new XYZ(3, 0, 10), new XYZ(3, 0, 0));

            List<Curve> profile1 = new List<Curve>() { l1, l2, l3, l4 };


            CurveLoop curveLoop = CurveLoop.Create(profile1);
            var solid = CreateCone(XYZ.Zero, curveLoop);
            OpenTransaction("223", solid);


        }



        public Solid CreateCone(XYZ center, CurveLoop curveLoop)
        {
            // Define a triangle in XZ plane

            //Frame frame = new Frame( center, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ);

            Frame frame = new Frame(center, XYZ.BasisX, XYZ.BasisZ, -XYZ.BasisY);


            Solid cone = GeometryCreationUtilities .CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI);

            return cone;
        }



    }




}
